<?
include('../conn.php');

$invoicefile = $_REQUEST['invoicefile'];

ECHO $invoicefile;
// $out_result = '';
// $res = mysql_query("CALL usp_process_invoice('invoice-2013-12-21-07-33-22.csv',$out_result)");
// if ($res === false) {
	// echo mysql_errno().': '.mysql_error();
// }
// else{
// echo 'proc executed'.$out_result;	
// }

$mysqli = new mysqli("68.178.216.107", "dbtransaction", "Admin1@3", "dbtransaction");
if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}

if (!$mysqli->query("SET @in_invoicefile = '".$invoicefile."'") || !$mysqli->query("SET @out_result = ''") || !$mysqli->query("CALL usp_process_invoice(@in_invoicefile,@out_result)")) {
    echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

if (!($res = $mysqli->query("SELECT @out_result as _p_out"))) {
    echo "Fetch failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

$row = $res->fetch_assoc();
echo $row['_p_out'];

echo 'proc executed';

?>
